package com.yy.permissions_general.module.system.roleAuth.service.impl;

import com.yy.permissions_general.module.system.roleAuth.entity.RoleAuth;
import com.yy.permissions_general.module.system.roleAuth.mapper.RoleAuthMapper;
import com.yy.permissions_general.module.system.roleAuth.service.RoleAuthService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.permissions_general.module.system.roleAuth.vo.RoleAuthVo;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色权限关联 服务实现类
 * </p>
 *
 * @author YY
 * @since 2021-10-07
 */
@Service
public class RoleAuthServiceImpl extends ServiceImpl<RoleAuthMapper, RoleAuth> implements RoleAuthService {

    /**
    * 分页查询列表
    * @param roleAuth
    * @return
    */
    @Override
    public  Page<RoleAuth>selectPageList(RoleAuth roleAuth, int limit, int page)  {
        Page pageContext = new Page(page,limit);
        Page<RoleAuth> pageList = this.baseMapper.selectPage(pageContext, roleAuth);
        return pageList;
    }

    @Override
    public int deleteByRoleId(String roleId) {
        Map<String,Object> map = new HashMap<>();
        map.put("role_id",roleId);
        return baseMapper.deleteByMap(map);
    }

    /**
    * 删除数据
    * @param id
    * @return
    */
    @Override
    public int deleteById(Integer id) {
        return baseMapper.deleteById(id);
    }

    /**
    * 批量删除
    * @param ids
    * @return
    */
    @Override
    public int deleteBatch(List<Long> ids) {
        return baseMapper.deleteBatchIds(ids);
    }

    /**
     * 根据角色ID获取权限
     * @param roleId 角色ID
     * @return
     */
    @Override
    public List<RoleAuthVo> getRoleAuthTree(Integer roleId) {
        return RoleAuthVo.roleAuthVoUtil(0,baseMapper.getRoleAuthTree(roleId));
    }

}

